﻿#include "stdafx.h"
#include "SceneLogin.h"
#include "SceneMgr.h"
#include "SceneCharacterMgr.h"
#include "Models_player.h"
#include "PlayerObject.h"
#include "TextureDrawObject.h"
#include "TextureDraw_flare.h"
#include "DlgServerList.h"

SceneLogin::SceneLogin()
{
}


SceneLogin::~SceneLogin()
{
	m_dlgLogin.DestroyWindow();
	m_dlgServerList.DestroyWindow();

	if (m_wnd_root)
	{
		m_wnd_root->destroy();
		m_wnd_root = nullptr;
	}
}

bool SceneLogin::Init()
{
	auto conn = MuNetConnect::GetInstance();
    conn->setListener(this);
	//conn->m_cs.m_cb_AfterConnect = std::bind(&SceneLogin::cb_AfterConnect_cs, this, _1);
	//conn->m_gs.m_cb_AfterConnect = std::bind(&SceneLogin::cb_AfterConnect_gs, this, _1);
	//conn->m_cs.m_cb_AfterClose = std::bind(&SceneLogin::cb_AfterClose_cs, this);
	//conn->m_gs.m_cb_AfterClose = std::bind(&SceneLogin::cb_AfterClose_gs, this);
	//conn->m_cs.m_cb_AfterUnpack = std::bind(&SceneLogin::DispatchPacket, this, _1, _2);
	//conn->m_gs.m_cb_AfterUnpack = conn->m_cs.m_cb_AfterUnpack;

	//char buf[260];
	//int n = GetCurrentDirectory(260, buf);
	//m_viewport1.Init(2.0f, 0.f, 0.1f);
	//m_viewport2.Init();
	m_wnd_root = CEGUI::WindowManager::getSingleton().loadLayoutFromFile("login.layout");
	CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow(m_wnd_root);
	//root->setHorizontalAlignment(CEGUI::HorizontalAlignment::HA_CENTRE);

	m_dlgServerList.InitWindow(m_wnd_root);
	m_dlgServerList.m_cb_selectLine = std::bind(&SceneLogin::cb_selectLine, this, _1, _2);

	m_dlgLogin.InitWindow(m_wnd_root);
	m_dlgLogin.m_cb_SignIn = std::bind(&SceneLogin::cb_login, this, _1, _2);


	if (!conn->isConnected_cs())
        conn->connectCs(conn->m_cs_ip.c_str(), conn->m_cs_port);
	else
        conn->RequestServerList();

	auto wnd = MainWin::GetInstance();
	window_size_callback(wnd->GetWidth(), wnd->GetHeight());
	m_gameObjList1.SetRootMatrixPtr(&m_camera.GetViewMatrix());
	//auto transRoot1 = GetTransformRoot(0);
	//transRoot1->SetLocalMatrix(m_camera.GetViewMatrix());

	m_mdls_logo.Load();

	auto skybox = new SkeletonAnimation;
	skybox->Init(&m_camera, &m_mdls_logo.m_skybox, &Shaders::GetInstance()->m_sBoneModel);
	skybox->SetLocalMatrix(glm::scale(glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, -957.0f, 464.5f)), glm::vec3(0.0032f)));
	m_gameObjList1.Add(skybox);
	//auto trans = skybox->m_transformObject.Add(glm::scale(glm::translate(0.0f, -957.0f, 464.5f), glm::vec3(0.0032f)));
	//transRoot1->AddChild(trans);

	auto sun = new SkeletonAnimation;
	sun->Init(&m_camera, &m_mdls_logo.m_sun, &Shaders::GetInstance()->m_sBoneModel);
	sun->SetLocalMatrix(glm::scale(glm::translate(glm::mat4(1.0f), glm::vec3(-8.0f, -801.0f, 467.5f)), glm::vec3(0.23f)));
	sun->m_animate.SetInterpolation(true);
	sun->m_animate.SetFrameRate(3.f);
	sun->SetColor(glm::vec4(0.45));
	m_gameObjList1.Add(sun);
	//trans = sun->m_transformObject.Add(glm::scale(glm::translate(-8.0f / 0.0032f, 156.0f / 0.0032f, 3.f / 0.0032f), glm::vec3(.23f / 0.0032f)), trans);
	//trans = sun->m_transformObject.Add(glm::scale(glm::translate(-8.0f, -801.0f, 467.5f), glm::vec3(0.23f)));
	//trans->SetColor(glm::vec4(0.45));
	//transRoot1->AddChild(trans);

	glm::vec3 shipPositions[3] = {
		glm::vec3(-49.5f, -877.0f, 465.0f),
		glm::vec3(28.5f, -893.5f, 465.0f),
		glm::vec3(-14.0f, -952.0f, 465.0f)
	};

	SkeletonAnimation *ships[3];
	SkeletonAnimation *waves[3];
	for (int i = 0; i < 3; i++)
	{
		waves[i] = new SkeletonAnimation(&m_camera, &m_mdls_logo.m_wave, &Shaders::GetInstance()->m_sBoneModel);
		ships[i] = new SkeletonAnimation(&m_camera, &m_mdls_logo.m_ship, &Shaders::GetInstance()->m_sBoneModel);
		ships[i]->m_animate.SetInterpolation(true);
		ships[i]->m_animate.SetFrameRate(4.0f);
		ships[i]->UseLight(0);
		ships[i]->SetLocalMatrix(glm::scale(glm::rotate(glm::translate(glm::mat4(1.0f), shipPositions[i]), glm::radians(180.0f), glm::vec3(0.f, 0.f, 1.f)), glm::vec3(0.056f)));
		ships[i]->AddChild(waves[i]);
		m_gameObjList1.Add(ships[i]);
	}
	//m_gameObjects[0].push_back(ship);
	//ship->m_animate.SetInterpolation(true);
	//ship->m_animate.SetFrameRate(4.0f);
	//ship->UseLight(0);
	//for (int i = 0; i < 3; i++)
	//{
	//	trans = ship->m_transformObject.Add(glm::scale(glm::rotate(glm::translate(shipPositions[i]), 180.0f, 0.f, 0.f, 1.f), glm::vec3(0.056f)));
	//	transRoot1->AddChild(trans);
	//}

	//m_gameObjects[0].push_back(wave);
	//for (int i = 0; i < 3; i++)
	//{
	//	trans = wave->m_transformObject.Add();
	//	ship->m_transformObject.Get(i)->AddChild(trans);
	//}
	//wave->m_transformObject.Add(glm::scale(glm::rotate(glm::translate(shipPositions[i]), 180.0f, 0.f, 0.f, 1.f), glm::vec3(0.056f)), transRoot1);

	auto muLogo = new SkeletonAnimation(&m_camera, &m_mdls_logo.m_muLogo, &Shaders::GetInstance()->m_sBoneModel);
	muLogo->SetLocalMatrix(glm::scale(glm::translate(glm::rotate(glm::mat4(1.0f), glm::radians(-10.0f), glm::vec3(1.0f, 0.0f, 0.0f)), glm::vec3(0.0f, -1045.0f, 322.4f)), glm::vec3(0.034f)));
	m_gameObjList1.Add(muLogo);
	//m_gameObjects[0].push_back(muLogo);
	//trans = muLogo->m_transformObject.Add(glm::scale(glm::translate(glm::rotate(-10.0f, 1.0f, 0.0f, 0.0f), 0.0f, -1045.0f, 322.4f), glm::vec3(0.034f)));
	//transRoot1->AddChild(trans);
	//trans = muLogo->m_skeletonAnimation.m_transformObject.Add(glm::scale(glm::rotate(180.0f, 0.0f, 0.0f, 1.0f), glm::vec3(0.5)), ship->m_skeletonAnimation.m_transformObject.Get(1));
	//trans->m_intermediateMatrices.push_back(ship->m_skeletonAnimation.m_animate.GetBoneTransformMatrix("Bone01"));

	faShi = new PlayerObject(MuType::Class_FaShi, &m_camera, &Shaders::GetInstance()->m_sBoneModel);
	//faShi->SetLocalMatrix(glm::scale(glm::rotate(glm::translate(glm::vec3(-30.f, -220.f, -115.f)), 0.0f, 0.0f, 0.0f, 1.0f), glm::vec3(0.66)));
	faShi->SetScale(0.66f);
	faShi->SetPosition(-30.f, -220.f, -115.f);
	faShi->m_intermediateMatrices.push_back(ships[2]->m_animate.GetBoneTransformMatrix("Bone01"));
	faShi->m_animate.SetAnimation(1, 0);
	faShi->UseLight(0);
	ships[2]->AddChild(faShi);
	//m_gameObjects[0].push_back(faShi);
	//trans = faShi->m_transformObject.Add(glm::scale(glm::rotate(glm::translate(glm::vec3(-30.f, -220.f, -115.f)), 0.0f, 0.0f, 0.0f, 1.0f), glm::vec3(0.66)));
	//trans->m_intermediateMatrices.push_back(ship->m_animate.GetBoneTransformMatrix("Bone01"));
	//ship->m_transformObject.Get(2)->AddChild(trans);
	//faShi->m_animate.SetAnimation(1, 0);
	//faShi->UseLight(0);

	zhanShi = new PlayerObject(MuType::Class_ZhanShi, &m_camera, &Shaders::GetInstance()->m_sBoneModel);
	//zhanShi->SetLocalMatrix(glm::scale(glm::rotate(glm::translate(glm::vec3(-94.f, -220.f, -115.f)), 0.0f, 0.0f, 0.0f, 1.0f), glm::vec3(0.66)));
	zhanShi->SetScale(0.66f);
	zhanShi->SetPosition(-94.f, -220.f, -115.f);
	zhanShi->m_intermediateMatrices.push_back(ships[2]->m_animate.GetBoneTransformMatrix("Bone01"));
	zhanShi->m_animate.SetAnimation(89, 0);
	zhanShi->UseLight(0);
	ships[2]->AddChild(zhanShi);
	//m_gameObjects[0].push_back(zhanShi);
	//trans = zhanShi->m_transformObject.Add(glm::scale(glm::rotate(glm::translate(glm::vec3(-94.f, -220.f, -115.f)), 0.0f, 0.0f, 0.0f, 1.0f), glm::vec3(0.66)));
	//trans->m_intermediateMatrices.push_back(ship->m_animate.GetBoneTransformMatrix("Bone01"));
	//ship->m_transformObject.Get(2)->AddChild(trans);
	//zhanShi->m_animate.SetAnimation(89, 0);
	//zhanShi->UseLight(0);

	auto gongJianShou = new PlayerObject(MuType::Class_GongJianShou, &m_camera, &Shaders::GetInstance()->m_sBoneModel);
	//gongJianShou->SetLocalMatrix(glm::scale(glm::rotate(glm::translate(glm::vec3(-94.f, -220.f, -115.f)), 0.0f, 0.0f, 0.0f, 1.0f), glm::vec3(0.66)));
	gongJianShou->SetScale(0.66f);
	gongJianShou->SetPosition(-94.f, -220.f, -115.f);
	gongJianShou->m_intermediateMatrices.push_back(ships[1]->m_animate.GetBoneTransformMatrix("Bone01"));
	gongJianShou->m_animate.SetAnimation(2, 0);
	gongJianShou->UseLight(0);
	ships[1]->AddChild(gongJianShou);
	//m_gameObjects[0].push_back(gongJianShou);
	//trans = gongJianShou->m_transformObject.Add(glm::scale(glm::rotate(glm::translate(glm::vec3(-94.f, -220.f, -115.f)), 0.0f, 0.0f, 0.0f, 1.0f), glm::vec3(0.66)));
	//trans->m_intermediateMatrices.push_back(ship->m_animate.GetBoneTransformMatrix("Bone01"));
	//ship->m_transformObject.Get(1)->AddChild(trans);
	//gongJianShou->m_animate.SetAnimation(2, 0);
	//gongJianShou->UseLight(0);

	g_centerPoint = glm::vec3(-94.f, -220.f, -115.f);
	g_scale = 0.66;

	//船尾火焰
	TextureDraw_flare *flares[4];
	m_texMgr.SetLoadDir("./Data/Effect/");
	for (int i = 0; i < 4; i++)
	{
		flares[i] = new TextureDraw_flare(&m_camera, m_texMgr.GetTexture("flare01.OZJ"), &Shaders::GetInstance()->m_sTexRender);
		flares[i]->SetAnchorPoint(glm::vec2(0.5f, 0.5f));
		auto mate = flares[i]->GetRender(0)->GetMaterial(0);
		mate->m_blend = true;
		mate->m_blendSfactor = GL_ONE;
		mate->m_blendDfactor = GL_ONE;
		flares[i]->ColorRandomRange(glm::vec4(180.f / 255, 109.f / 255, 65.f / 255, 1.f), 0.5f, 1.0f, 20);
	}
	flares[0]->m_intermediateMatrices.push_back(ships[0]->m_animate.GetBoneTransformMatrix("Bone01"));
	flares[1]->m_intermediateMatrices.push_back(ships[0]->m_animate.GetBoneTransformMatrix("Bone02"));
	flares[2]->m_intermediateMatrices.push_back(ships[1]->m_animate.GetBoneTransformMatrix("Bone01"));
	flares[3]->m_intermediateMatrices.push_back(ships[1]->m_animate.GetBoneTransformMatrix("Bone02"));
	ships[0]->AddChild(flares[0]);
	ships[0]->AddChild(flares[1]);
	ships[1]->AddChild(flares[2]);
	ships[1]->AddChild(flares[3]);
	//auto flare = new TextureDraw_flare(&m_camera, m_texMgr.GetTexture("flare01.OZJ"), &Shaders::GetInstance()->m_sTexRender);
	//flare->SetAnchorPoint(glm::vec2(0.5f, 0.5f));
	//flare->GetRender(0)->GetMaterial(0)->m_blend = true;
	//flare->GetRender(0)->GetMaterial(0)->m_blendSfactor = GL_ONE;
	//flare->GetRender(0)->GetMaterial(0)->m_blendDfactor = GL_ONE;
	//flare->ColorRandomRange(glm::vec4(180.f / 255, 109.f / 255, 65.f / 255, 1.f), 0.5f, 1.0f, 20);
	//m_gameObjects[0].push_back(flare);
	//
	//trans = flare->m_transformObject.Add();
	//trans->m_intermediateMatrices.push_back(ship->m_animate.GetBoneTransformMatrix("Bone01"));
	//ship->m_transformObject.Get(0)->AddChild(trans);

	//trans = flare->m_transformObject.Add();
	//trans->m_intermediateMatrices.push_back(ship->m_animate.GetBoneTransformMatrix("Bone02"));
	//ship->m_transformObject.Get(0)->AddChild(trans);

	//trans = flare->m_transformObject.Add();
	//trans->m_intermediateMatrices.push_back(ship->m_animate.GetBoneTransformMatrix("Bone01"));
	//ship->m_transformObject.Get(1)->AddChild(trans);

	//trans = flare->m_transformObject.Add();
	//trans->m_intermediateMatrices.push_back(ship->m_animate.GetBoneTransformMatrix("Bone02"));
	//ship->m_transformObject.Get(1)->AddChild(trans);

	//m_texData1.Init(&m_camera, &Shaders::GetInstance()->m_sTexRender);
	//for (auto &tm : m_texHandle_flare01)
	//{
	//	auto t = m_texData1.Add(m_texMgr.GetTexture("flare01.jpg"));
	//	t->SetAnchorPoint(0.5f, 0.5f);
	//	//t->SetColor(glm::vec4(145.f / 255, 86.f / 255, 44.f / 255, 1.f));
	//	t->SetColor(glm::vec4(180.f / 255, 109.f / 255, 65.f / 255, 1.f));
	//	//t->SetScale(0.08);
	//	tm.Init(t);
	//	tm.SetScale(1.4f);

	//模型加载
	//m_texMgr.SetLoadDir("Data\\Logo\\");
	////头像
	//Model::LoadSerialName(m_mdl_face, 4, "Data\\Logo\\face%02d.bmd", 1, &m_texMgr);
	////海面,船尾波浪,"MU"字体logo,日出位置的一个动态模型,选择人物界面的背景
	//Model::LoadSerialName(m_mdl_logo, 5, "Data\\Logo\\logo%02d.bmd", 1, &m_texMgr);
	////船
	//m_texMgr.SetLoadDir("Data\\Object1\\");
	//fok = m_mdl_ship1.Load("Data\\Object1\\Ship01.bmd", &m_texMgr);
	////模型设置
	////海面
	//m_mdl_logo[0].m_materials[1]->m_blend = true;
	//m_mdl_logo[0].m_materials[1]->m_blendDfactor = GL_ONE;
	//m_mdl_logo[0].m_materials[1]->m_blendSfactor = GL_ONE;
	//m_mdl_logo[0].m_materials[2]->m_textures[0]->SetTexParam_WRAP_CLAMP_TO_EDGE();
	//m_mdl_logo[0].m_materials[3]->m_textures[0]->SetTexParam_WRAP_CLAMP_TO_EDGE();
	////船尾波浪
	//m_mdl_logo[1].m_materials[0]->m_blend = true;
	//m_mdl_logo[1].m_materials[0]->m_blendDfactor = GL_ONE;
	//m_mdl_logo[1].m_materials[0]->m_blendSfactor = GL_ONE;
	////"MU"字体logo
	//m_mdl_logo[2].m_materials[1]->m_blend = true;
	//m_mdl_logo[2].m_materials[1]->m_blendDfactor = GL_ONE;
	//m_mdl_logo[2].m_materials[1]->m_blendSfactor = GL_ONE;
	////m_mdl_logo[2].m_materials[0].m_material.diffuse = glm::vec4(0.0f);
	////日出位置的一个动态模型
	//m_mdl_logo[3].m_materials[0]->m_blend = true;
	//m_mdl_logo[3].m_materials[0]->m_blendDfactor = GL_ONE;
	//m_mdl_logo[3].m_materials[0]->m_blendSfactor = GL_ONE;
	////渲染对象设置
	////海面
	//m_obj_logo01.Init(&m_camera, &Shaders::GetInstance()->m_sBoneModel, &m_mdl_logo[0]);
	//m_obj_logo01.AllocRenderInfo(1);
	//m_obj_logo01.SetTransform(0, glm::scale(glm::translate(0.0f, -957.0f, 464.5f), glm::vec3(0.0032f)));
	//auto mate = m_obj_logo01.m_renders[0].GetMaterial(1);
	//mate->EnableTextureOffset(true);
	//mate->SetTextureOffsetSpeed(glm::vec2(0.f, -0.3f));
	////m_texOffset_logo01 = m_obj_logo01.m_renders[0].GetMaterial(1)->m_textureOffset;
	////日出位置的一个动态模型
	//m_obj_logo04.Init(&m_camera, &Shaders::GetInstance()->m_sBoneModel, &m_mdl_logo[3]);
	//m_obj_logo04.AllocRenderInfo(1);
	//m_obj_logo04.SetTransform(0, glm::scale(glm::translate(-8.0f, -801.0f, 467.5f), glm::vec3(0.23f)));
	//m_obj_logo04.SetColor(0, glm::vec4(0.45));
	//m_obj_logo04.m_animate.SetFrameRate(4.0f);
	////船
	//m_obj_ship1.Init(&m_camera, &Shaders::GetInstance()->m_sBoneModel, &m_mdl_ship1);
	//m_obj_ship1.m_animate.SetFrameRate(4.0f);
	//m_obj_ship1.m_animate.SetInterpolation(true);
	//m_obj_ship1.UseLight(0);

	//glm::vec3 ris_trans[3] = {
	//	glm::vec3(-49.5f, -877.0f, 465.0f),
	//	glm::vec3(28.5f, -893.5f, 465.0f),
	//	glm::vec3(-14.0f, -952.0f, 465.0f)
	//};
	//for (int i = 0; i < 3; i++)
	//{
	//	m_ri_ship1[i].transform = glm::scale<float>(glm::rotate<float>(glm::translate<float>(ris_trans[i]), 180.0f, 0, 0, 1), glm::vec3(0.056f));
	//	m_ri_ship1[i].color = glm::vec4(1.0f);
	//	m_obj_ship1.m_renderInfos.push_back(&m_ri_ship1[i]);
	//}
	////船尾波浪
	//m_obj_logo02.Init(&m_camera, &Shaders::GetInstance()->m_sBoneModel, &m_mdl_logo[1]);
	//mate = m_obj_logo02.m_renders[0].GetMaterial(0);
	//mate->EnableTextureOffset(true);
	//mate->SetTextureOffsetSpeed(glm::vec2(0.f, -0.3f));
	////m_texOffset_logo02 = m_obj_logo02.m_renders[0].GetMaterial(0)->m_textureOffset;
	//for (int i = 0; i < 2; i++)
	//{
	//	m_ri_logo02[i].transform = glm::scale<float>(glm::rotate<float>(glm::translate<float>(ris_trans[i]), 180.0f, 0, 0, 1), glm::vec3(0.056f));
	//	m_ri_logo02[i].color = glm::vec4(1.0f);
	//	m_obj_logo02.m_renderInfos.push_back(&m_ri_logo02[i]);
	//}
	////"MU"字体logo
	//m_obj_logo03.Init(&m_camera, &Shaders::GetInstance()->m_sBoneModel, &m_mdl_logo[2]);
	//m_obj_logo03.AllocRenderInfo(1);
	//m_obj_logo03.SetTransform(0, glm::scale(glm::translate(glm::rotate(-10.0f, 1.0f, 0.0f, 0.0f), 0.0f, -1045.0f, 322.4f), glm::vec3(0.034f)));
	//m_obj_logo03.SetColor(0, glm::vec4(0.0f));


	//m_renderObjects[0].push_back(&logoFont->m_skeletonAnimation);
	////船尾火焰
	//m_texMgr.SetLoadDir("Data\\Effect\\");
	//m_texData1.Init(&m_camera, &Shaders::GetInstance()->m_sTexRender);
	//for (auto &tm : m_texHandle_flare01)
	//{
	//	auto t = m_texData1.Add(m_texMgr.GetTexture("flare01.jpg"));
	//	t->SetAnchorPoint(0.5f, 0.5f);
	//	//t->SetColor(glm::vec4(145.f / 255, 86.f / 255, 44.f / 255, 1.f));
	//	t->SetColor(glm::vec4(180.f / 255, 109.f / 255, 65.f / 255, 1.f));
	//	//t->SetScale(0.08);
	//	tm.Init(t);
	//	tm.SetScale(1.4f);
	//}
	//m_texData1.Make();
	//glm::mat4 *shipBoneMat[2];
	//shipBoneMat[0] = m_obj_ship1.m_animate.GetBoneTransformMatrix("Bone01");
	//shipBoneMat[1] = m_obj_ship1.m_animate.GetBoneTransformMatrix("Bone02");
	//for (int i = 0; i < 4; i++)
	//{
	//	m_texHandle_flare01[i].m_mats.push_back(shipBoneMat[i % 2]);
	//	m_texHandle_flare01[i].m_mats.push_back(&m_obj_ship1.m_renderInfos[i / 2]->transform);
	//	m_texHandle_flare01[i].m_mats.push_back(&m_camera.GetView());
	//	m_texHandle_flare01[i].Update();
	//}
	//m_texData1.m_render.GetMaterial(0)->m_blend.enable = true;
	//m_texData1.m_render.GetMaterial(0)->m_blend.dfactor = GL_ONE;
	//m_texData1.m_render.GetMaterial(0)->m_blend.sfactor = GL_ONE;
	//m_texData1.SetIsChange();
	//人物
	//ris_trans[0] = glm::vec3();
	//ris_trans[1] = glm::vec3();
	//ris_trans[2] = glm::vec3();
	//auto mdls_player = Models_player::GetInstance();
	//int mdls_count;
	//auto mdls = mdls_player->GetBody(MuType::Class_ZhanShi, &mdls_count);
	//m_ply_zs.Init(&m_camera, &Shaders::GetInstance()->m_sBoneModel, mdls_player->GetPlayerAnimation(), mdls_count);
	//for (int i = 0; i < mdls_count; i++) m_ply_zs.setModel(i, mdls + i);
	//m_ply_zs.m_animate.SetAnimation(4, 0);
	//m_ply_zs.UseLight(0);
	//m_ply_zs.AllocRenderInfo(1);
	//m_ply_zs.SetTransform(0, glm::scale(glm::translate(glm::rotate(-10.0f, 1.0f, 0.0f, 0.0f), 0.0f, 0.0f, 0.0f), glm::vec3(1.034f)));


	//g_viewPoint = glm::vec4(0.0f, 0.0f, 0.0f, 0.001f);
	return true;
}

void SceneLogin::Update()
{
	//auto conn = MuNetConnect::GetInstance();
	//if (conn->m_cs.m_havePack)
	//{
	//	DispatchPacket(conn->m_cs);
	//}
	//if (conn->m_gs.m_havePack)
	//{
	//	DispatchPacket(conn->m_gs);
	//}
	//*
	m_viewport1.Use();

	//zhanShi->m_transformObject.Get(0)->SetLocalMatrix(glm::scale(glm::rotate(glm::translate(g_centerPoint), 0.0f, 0.0f, 0.0f, 1.0f), glm::vec3(0.66f)));
	//Scene::Update();
	m_gameObjList1.Update();
	//m_texOffset_logo01[1] -= FrameTime::GetInstance()->GetDeltaTime()*0.3f;
	//m_obj_logo01.Update();

	//m_obj_logo04.Update();
	//m_obj_ship1.Update();
	//m_texOffset_logo02[1] -= FrameTime::GetInstance()->GetDeltaTime()*0.3f;
	//m_obj_logo02.Update();

	//auto ship1BoneMat = m_obj_ship1.m_renderInfos[1]->transform * (*m_obj_ship1.m_animate.GetBoneTransformMatrix("Bone01"));
	//m_ply_zs.m_renderInfos[0]->transform = ship1BoneMat * glm::translate<float>(-100, -200, -150) * glm::rotate<float>(180, 0, 0, 1) * glm::scale(glm::vec3(1.5f));
	//m_ply_zs.Update();
	//m_obj_logo03.Update();

	static DWORD timeLogo03 = 0;
	if (timeLogo03 < 2000)
	{
		timeLogo03 += FrameTime::GetInstance()->GetDeltaTimeMs();
		if (timeLogo03 >= 2000)
		{
			//m_obj_logo03.SetColor(0, glm::vec4(1.0f));
			//播放声音 "Data\Sound\iTitle.wav"
			MyPlaySound(L"Data\\Sound\\iTitle.wav");
		}
	}

	//glm::mat4 *mats2 = 0;
	//m_obj_ship1.m_animate.GetBoneTransformMatrixs(&mats2);
	//auto pos3 = mats2[8] * glm::vec4(0.f, 0.f, 0.f, 1.f);
	//auto pos = m_camera.GetView() * m_obj_ship1.m_renderInfos[0]->transform * pos3;
	//m_texHandle_flare01[0]->SetPosition(pos.x, pos.y, pos.z);
	//m_texHandle_flare01[0]->MakeVertexs();
	//pos = m_camera.GetView()*m_obj_ship1.m_renderInfos[1]->transform*pos3;
	//m_texHandle_flare01[2]->SetPosition(pos.x, pos.y, pos.z);
	//m_texHandle_flare01[2]->MakeVertexs();

	//pos3 = mats2[9] * glm::vec4(0.f, 0.f, 0.f, 1.f);
	//pos = m_camera.GetView() * m_obj_ship1.m_renderInfos[0]->transform * pos3;
	//m_texHandle_flare01[1]->SetPosition(pos.x, pos.y, pos.z);
	//m_texHandle_flare01[1]->MakeVertexs();
	//pos = m_camera.GetView()*m_obj_ship1.m_renderInfos[1]->transform*pos3;
	//m_texHandle_flare01[3]->SetPosition(pos.x, pos.y, pos.z);
	//m_texHandle_flare01[3]->MakeVertexs();
	static float frameTimeCount;
	frameTimeCount += FrameTime::GetInstance()->GetDeltaTime()*20.f;
	glm::vec3 color = glm::vec3(180.f / 255, 109.f / 255, 65.f / 255);
	//for (auto &texHanld : m_texHandle_flare01)
	//{
	//	if (frameTimeCount > 1.f)
	//	{
	//		auto r = RangedRand(0.6f, 1.0f);
	//		auto color2 = color*r;
	//		texHanld.m_texHandle->SetColor(color2.r, color2.g, color2.b);
	//	}
	//	texHanld.Update();
	//}
	//if (frameTimeCount > 1.f) frameTimeCount = 0.f;
	////m_texData1.SetIsChange();
	//m_texData1.Draw();
	//SetCamera();
	//m_obj_logo03.SetTransform(glm::scale(glm::translate(glm::rotate(-10.0f, 1.0f, 0.0f, 0.0f), 0.0f, g_viewPoint.y, g_viewPoint.z), glm::vec3(g_viewPoint.w)));
	//m_camera.LookAt(0, -200, 0, 0, g_viewPoint.y, 0, 0, 0, 1);
	//m_rd_face03.Draw();
	//auto m1 = glm::translate<float>(g_viewPoint.x, g_viewPoint.y, g_viewPoint.z);
	//m1 = glm::rotate<float>(m1, 180.0f, 0, 0, 1);

	m_viewport2.Use();
	//auto m1 = glm::translate<float>(0.f, 0.f, g_viewPoint.z+0.2);
	//auto m2 = glm::rotate<float>(-90, 1, 0, 0);
	//auto m3 = glm::scale<float>(glm::vec3(g_viewPoint.w));
	//m_obj_logo03.SetTransform(m2 * m1 * m3);
	////m_obj_logo03.SetTransform(glm::scale(glm::rotate(glm::translate(glm::rotate(-90.0f, 0.0f, 1.0f, 0.0f), 0.0f, g_viewPoint.y, g_viewPoint.z),g_viewPoint.x,1.0f,0.f,0.f), glm::vec3(g_viewPoint.w)));
	//m_obj_logo03.Update();
	return;
	//*/

	//glLoadIdentity();
	//glTranslatef(0, g_viewPoint.y, g_viewPoint.z);
	//glRotatef(-90, 1, 0, 0);
	//static float r = 0;
	//r += 0.1f;
	//glRotatef(r, 0, 0, 1);
	////glEnable(GL_POINT_SMOOTH);
	////glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
	//glColor3f(1, 1, 1);
	//glPointSize(5);
	//int count = 0;

	//glm::mat4 * mats = 0;
	//count = m_obj_ship1.m_animate.GetBoneTransformMatrixs(&mats);
	//int i = 0;
	//glm::vec4 pos1, pos2;
	//glm::vec4 v0 = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
	//float fcolor = 0.4f;
	//for (auto &n : m_mdl_ship1.m_animationData.nodes)
	//{
	//	if (n.parentID == -1)
	//	{
	//		pos1 = mats[i] * v0;
	//		pos1 = mats[i][3];
	//		glColor3f(1, 1, 1);
	//		glBegin(GL_POINTS);
	//		glVertex3fv(&pos1[0]);
	//		glEnd();
	//	}
	//	else
	//	{
	//		glColor3ub(255, i / 4 * 100, i % 4 * 80);
	//		pos1 = mats[n.parentID] * v0;
	//		pos2 = mats[i] * v0;
	//		pos1 = mats[n.parentID][3];
	//		pos2 = mats[i][3];
	//		glBegin(GL_POINTS);
	//		glVertex3fv(&pos2[0]);
	//		glEnd();
	//		glBegin(GL_LINES);
	//		glVertex3fv(&pos1[0]);
	//		glVertex3fv(&pos2[0]);
	//		glEnd();
	//	}
	//	i++;
	//}

}

void SceneLogin::window_size_callback(int width, int height)
{
	m_viewport1.SetSize(width, height);
	m_viewport1.ClipViewportH(1.0/6.0);
	m_viewport1.AspectRatio(2.0f);
	m_viewport2.SetSize(width, height);
	m_viewport2.AspectRatio(640.0 / 480.0);
	auto wnd = CEGUI::System::getSingleton().getDefaultGUIContext().getRootWindow();
	wnd->setWidth(CEGUI::UDim(0.0f, m_viewport1.m_width));
	//CEGUI::System::getSingleton().notifyDisplaySizeChanged(CEGUI::Sizef(static_cast<float>(m_viewport2.m_width), static_cast<float>(m_viewport2.m_height)));
	m_camera.Perspective(45, m_viewport1.m_width / (float)m_viewport1.m_height, 20, 2800);
	//float r = glm::pi<float>() / 180.0f;
	//float z1 = tan(r*10.0f) * 1000;
	//m_camera.LookAt(0, -1000, 500, 0, 0, 500-z1, 0, 0, 1);
	//m_camera.LookAt(0, -1500, 0, 0, 0, 0, 0, 0, 1);
	auto m1 = glm::rotate<float>(glm::mat4(1.0f), glm::radians(-80.0f), glm::vec3(1, 0, 0));
    m1 = glm::translate<float>(m1, glm::vec3(0, 1000.781f, -500));
	m_camera.SetViewMatrix(m1);

	auto r2 = m_viewport2.m_width / (float)m_viewport2.m_height;
	//auto h2 = m_viewport2.height / 2;
	//m_camera2->Ortho(-r2, r2, -1, 1, -1, 200);
	//m_camera2.LookAt(0, g_viewPoint.y, 0, 0, 1000, 0, 0, 0, 1);
}

void SceneLogin::on_cs_serverList(MuPack::ServerList * serverList)
{
	int group;
	DlgServerList::Info slInfo;
	m_dlgServerList.m_groups.clear();
	bool have;
	for (int i = 0; i < serverList->count; i++)
	{
		auto &info = serverList->infos[i];
		group = info.code / 20;
		slInfo.code = info.code;
		slInfo.rate = info.rate / 100.0f;
		slInfo.name = "小服";
		have = false;
		for (auto &g : m_dlgServerList.m_groups)
		{
			if (g.number == group)
			{
				have = true;
				g.list.push_back(slInfo);
			}
		}
		if (!have)
		{
			m_dlgServerList.m_groups.push_back(DlgServerList::Group());
			auto &g = m_dlgServerList.m_groups.back();
			g.number = group;
			g.name = "大服";
			g.list.push_back(slInfo);
		}
	}
	//更新列表显示
	m_dlgServerList.UpdateWindow();
}

void SceneLogin::on_cs_serverAddr(MuPack::ServerAddr* serverAddr)
{
	auto conn = MuNetConnect::GetInstance();
	conn->connectGs(serverAddr->ip, serverAddr->port);
	OutputDebugStringA(serverAddr->ip);
}

void SceneLogin::cb_selectLine(int groupIndex, int lineIndex)
{
	auto conn = MuNetConnect::GetInstance();
	conn->m_gs_serverCode = m_dlgServerList.GetServerCode();
	conn->RequestServerAddr(conn->m_gs_serverCode);
}

void SceneLogin::OnGameObjIdAndVersion(MuPack::GameObjIdAndVersion *idver)
{
	auto conn = MuNetConnect::GetInstance();
	conn->m_gameObjId = ntohs(idver->gameObjId);
	_ASSERT(sizeof(idver->version) == 3);
	memcpy(conn->m_serverVersion, idver->version, 3);
	conn->m_serverVersion[3] = 0;
}

void SceneLogin::cb_login(char *username, char *password)
{
	auto conn = MuNetConnect::GetInstance();
	conn->Login(username, password);
}

/*
0密码错误
1通过
2帐号错误
3该帐号正在使用中
4本服务器容纳的人数已满
5这是目前被禁止使用的帐号
6您的游戏版本不对请到官方网站下载最新的版本
7连接发生错误
8失败3次连接中断
9连接发生错误
10本帐号的使用期限已到
11本帐号的储值点数不足
12这个IP的使用期限已到期
*/
void SceneLogin::on_gs_loginResult(u_char status)
{
	OutputDebugStringA("login state:");
	dbgNum(status);
	if (status == 1)
	{
		m_dlgLogin.Hide();
		SceneMgr::GetInstance()->ReplaceScene(SceneCharacterMgr::Create());
    }
    else {
        OutputInformation("login result: %d", (u_int)status);
    }
}

void SceneLogin::on_cs_firstResponse()
{
    MuNetConnect::GetInstance()->RequestServerList();
}

void SceneLogin::on_gs_connect(bool status)
{
    if (status)
    {
        m_dlgLogin.Show();
    }
    else
    {
        OutputInformation("gs connect error");
    }
}

void SceneLogin::on_cs_close()
{
    OutputInformation("cs connect close");
}

void SceneLogin::on_gs_close()
{
    OutputInformation("gs connect close");
}
